<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<jsp:include page="../../inc.jsp"></jsp:include>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			div#tb ul{
				list-style:none;
				margin-top: 5px;
				margin-left:10px;
			}
			div#tb ul li{
				list-style:none;
				float: left;
				margin-left: 5px
			}
		</style>
	</head>
	<body>
		<script type="text/javascript">
			var dg;
			var url;
			
			function add(){
				openDialog('添加会议','');
			}
			function addFiles(){
				$('#fs').click();
			}
			function edit(index){
				dg.datagrid('selectRow',index);
				var row = dg.datagrid('getSelected');
				openDialog('修改会议',row);
			}
			function joinMeeting(index){
				dg.datagrid('selectRow',index);
				var row =  dg.datagrid('getSelected');
				row = JSON.stringify(row);
				console.log(row);
				$.ajax({
					type:'post',
					url:'${ctx}/meetingC/join.coc',
					data:{
						datas:row
					},
					dataType:'json',
					success:function(r){
						alert(r.msg);
						dg.datagrid('reload');
					}
				});
			}
			function openDialog(title,row){
				$('body').append('<div id="d1"></div>');
				var url='';
				var value='';
				if(row!=''){
					alert("进行修改");
					url='${ctx}/meetingC/';
				}else{
					alert("进行增加");
				}
				//$('#d1').dialog({
				parent.$.modalDialog({		
					href:'${ctx}/meetingC/aoe.coc',
					title:title,
					width:500,
					height:400,
					modal:true,
					buttons:[{
						text:'保存',
						iconCls:'icon-save',
						plain:true,
						handler:function(){
							//var f = $('#adDateForm');
							var f = parent.$.modalDialog.handler.find('#adDateForm');
							if(f.form("validate")){
								$.ajax({
									type:'post',
									url:'${ctx}/meetingC/editMeeting.coc',
									data:f.serialize(),
									dataType:'json',
									success:function(r){
										if(r.is){
											//$('#d1').dialog('destroy');//销毁
											parent.$.modalDialog.handler.dialog('close');
											dg.datagrid('reload');//重新加载数据
										}
									}
								});
							}else{
								alert("格式不正确");
							}
						
						}
					},{
						text:'取消',
						iconCls:'icon-cancel',
						plain:true,
						handler:function(){
							//$('#d1').dialog('destroy');//销毁
							parent.$.modalDialog.handler.dialog('close');
						}
					}]
				});
			}
				
			function getFind(){
				url="${ctx}/meetingC/findMine.coc";
				reloadDg(url);
			}
			$(function(){
				url = "${ctx}/meetingC/find2.coc";
				reloadDg(url);
				$('#fs').change(function(e){				
					//var formdata = new FormData(document.getElementById('fs'));
					console.log(file);
					var option={
						url:'${ctx}/meetingC/addFiles.coc',
						type:'post',
						dataType:'json',
						timeout:10000,
						contentType:"text/html;charset=utf8",
						success:function(r){
							alert(r.msg);
						}
					};
					$('#fsForm').ajaxSubmit(option);
					alert("提交表单");					
				});
			});
			
			function reloadDg(url){
				dg=$('#administerTable').datagrid({
					fit:true,
					singleSelect:true,
					url:url,
					columns:[[
					    {field:'ck',checkbox:true,},
					    {field:'id',title:'编号',hidden:true},
						{field:'name',title:'主题'},
						{field:'startDate',title:'时间',
							formatter:function(v,r,i){
								if(v!=undefined){
									v = v.substring(0,10);
								}
								return v;
							}},
						{field:'address',title:'地点'},
						{field:'dorm',title:'是否住宿',
							formatter:function(v,r,i){
								if(v==0){
									v='是';
								}else{
									v='否';
								}
								return v;
							}},
						{field:'introduce',title:'内容'},
						{field:'synopsis',title:'简介'},
						{field:'political',title:'政党'},
						{field:'cocJob',title:'商会职务'},
						{field:'files',title:'文件',
							formatter:function(v,r,i){
								var fs = r.fs;
								if(fs!=null){ v = fs.length; }
								else{ v = 0; }
								return v;
							}
						},
						{field:'join',title:'是否参加会议',
							formatter:function(v,r,i){
 								var menber = r.menber;
								if(menber!=null){
									v = "已参加/会议签到";
								}else{
									v = '没有参加';
								}
								return v; 
							}
						},
						{field:'ac',title:'操作',
							formatter:function(v,r,i){
 								var menber = r.menber;
								if(menber!=null){
									v = "";
								}else{
									v = '<a onclick="joinMeeting('+i+')" href="#" >参加会议</a>/';
								}
								return v+'<a onclick="addFiles()" href="#">添加文件</a>';
							}
						},
						{field:'ac2',title:'操作2',
							formatter:function(v,r,i){
 								var menber = r.menber;
								if(menber!=null){
									v = '<a onclick="edit('+i+')" href="#" >修改</a>/';
								}else{
									v = "";
								}
								return v+'<a onclick="addFiles()" href="#">添加文件</a>';
							}
						}
					]]
				});
			}
		</script>
		<div>
		<input type="hidden" value="${flat }" id="flat"/>
		<form id="fsForm" enctype="multipart/form-data"><input type="file" id="fs" name="fs" style="display:none" /></form>
			
		</div>
		<div class="easyui-layout" fit=true>
			<div id="" 
			 data-options="region:'north',border:false" style="height:60px;min-width: 600px;">
			 <div id="tb" style="width: 98%;height:45px;" 
			  border: 1px solid skyblue;margin: 0 auto;">
			 	<ul>
			 		<li class="easyui-linkbutton" onclick="add()" iconCls="icon-eadd">新增</li>
			 	</ul>
			 	<ul>
			 		<li class="easyui-linkbutton" onclick="getFind()" iconCls="icon-eadd">我参加的会议</li>
			 	</ul>
			 </div>
			 </div>
			<div id ="" 
			 data-options="region:'center'" style="padding:5px;background:#eee;">
				<table id="administerTable" >
					<tr><th>Header</th></tr>
		    		<tr><td>Data</td></tr>
		    	</table>
			</div>
		</div>

	</body>
</html>
